package com.zlcx.tz.live.domain.backup;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zlcx.tz.live.domain.TimeLearnRoomSeatsDO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @author anjl
 * 计时学习自习室座位信息
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "tz_time_learn_room_seats_backup")
@JsonSerialize
@DynamicUpdate
@DynamicInsert
public class TimeLearnRoomSeatsBackUpDO implements Serializable {

    private static final long serialVersionUID = -1605594002971588412L;
    @Id
    @GeneratedValue
    private Long id;
    /**
     * 进入房间记录id
     */
    private Long joinRoomId;

    /**
     * 房间id
     */
    private Long roomId;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 入座时间
     */
    private Date seatingTime;

    /**
     * 结束时间
     */
    private Date sitUpTime;

    /**
     * 学习内容id
     */
    private Long contentId;

    /**
     * 学习内容
     */
    private String studyContent;

    /**
     * 计时分钟数
     */
    private Integer minutes;

    /**
     * 座位编号
     */
    private Integer num;

    private Integer useOtherApps;


    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @UpdateTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    public static TimeLearnRoomSeatsBackUpDO from(TimeLearnRoomSeatsDO seat) {
        return Objects.isNull(seat) ? null :
                TimeLearnRoomSeatsBackUpDO
                        .builder()
                        .id(seat.getId())
                        .userId(seat.getUserId())
                        .useOtherApps(seat.getUseOtherApps())
                        .studyContent(seat.getStudyContent())
                        .seatingTime(seat.getSeatingTime())
                        .sitUpTime(seat.getSitUpTime())
                        .num(seat.getNum())
                        .roomId(seat.getRoomId())
                        .createTime(seat.getCreateTime())
                        .updateTime(seat.getUpdateTime())
                        .contentId(seat.getContentId())
                        .minutes(seat.getMinutes())
                        .build();
    }



}